<?php

namespace App\Service\Index;

use App\Helpers\AliyunUtil;
use App\Model\DiscountVideoUsers;
use App\Model\Message;
use App\Model\UserProfile;
use App\Service\BaseService;
USE App\Model\Setting\SettingAppHidden;

/**
 * APP信息
 */
class AppInfoService extends BaseService
{
    public function handle()
    {
        $appId = $this->request->input('appid', 0);
        $version = $this->request->input('version', '');
        $channel = $this->request->input('channel', 0);
        if(empty($appId) || empty($version) || empty($channel)){
            $appNav = 1;
            $shortVideo = 1;
        }else{
            $appNav = SettingAppHidden::getAppExamine($appId, $version, $channel);
            $shortVideo = SettingAppHidden::checkModuleHiddenByUser($this->getUserId(), $appId, $version, $channel, SettingAppHidden::FUNC_VIDEO);
        }

        $userId = $this->getUserId();
        $profile = UserProfile::getProfile($userId);
        $clearMsgMinutes = intval(env('CLEAR_MSG_OFFTIME', 86400) / 60);
        $ret = [
            //用户协议
            'protocol_link' => 'http://www.hudongailian.com/xinmi/protocol_ll_nige.html',
            //隐私协议
            'private_link' =>  'http://www.hudongailian.com/xinmi/protocol_ll_nige.html',
            //消息页面 - 自动打招呼入口
            'auto_msg_show' => $profile->gender == 1 ? 0 : 1,
            //域名配置
            'asset_host' => [
                'image' => AliyunUtil::IMG_HOST,
                'voice' => AliyunUtil::VOICE_HOST,
                'video' => AliyunUtil::VOICE_HOST,
            ],
            //邀请入口
            'show_invite' => 1,
            //每日任务入口
            'show_task' => 1,
            //首页榜单入口
            'show_rank' => 0,
            //清除消息记录周期（分钟）
            'clear_msg_minutes' => $clearMsgMinutes,
            //主播搭讪入口
            'show_hit' => 0,
            'app_nav' => $appNav,
            'short_video' => $shortVideo,
            'dis_video_status' => DiscountVideoUsers::getStatus($this->getUserId())
        ];
        //清理消息
        Message::cmdClearMsg($userId, $clearMsgMinutes);
        return $ret;
    }
}
